﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace Extjs_ReGSharp.Sorting
{
	internal class IntComparer<T> : IDefaultComparer<T>
	{
		#region IDefaultComparer<T> Members

		public int Compare(T firstVar, T secondVar, System.Reflection.PropertyInfo propertyToCompare)
		{
			int? firstVarPropertyValue = (int?)propertyToCompare.GetValue(firstVar, null);
			int? secondVarPropertyValue = (int?)propertyToCompare.GetValue(secondVar, null);

			if (secondVarPropertyValue == null)
			{
				return 1;
			}

			if (firstVarPropertyValue == null)
			{
				return -1;
			}

			return firstVarPropertyValue.Value - secondVarPropertyValue.Value;
		}

		#endregion
	}
}
